package com.mrd.util;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.SqlDateConverter;

public class BeanUtilExt extends BeanUtils {

  static {
    // 注册sql.date的转换器，即允许BeanUtils.copyProperties时的源目标的sql类型的值允许为空
    ConvertUtils.register(new SqlDateConverter(), java.util.Date.class);
    // // 在封装之前 注册转换器
    ConvertUtils.register(new DateTimeConverter(), java.util.Date.class);
  }

  public static void copyProperties(Object target, Object source)
      throws InvocationTargetException, IllegalAccessException {
    // 支持对日期copy
    org.apache.commons.beanutils.BeanUtils.copyProperties(target, source);
  }
}
